<template>
  <div id="ContactUs">
    <div class="banner container-fuild text-center">上传设备</div>
    <div class="container">
      <van-divider />

      <el-input placeholder="请输入编号" v-model="dnum">
        <template slot="prepend">编号</template>
      </el-input>

      <el-input placeholder="请输入名称" class="mt2" v-model="dname">
        <template slot="prepend">名称</template>
      </el-input>
      <el-input placeholder="请输入规格" class="mt2" v-model="guige">
        <template slot="prepend">规格</template>
      </el-input>
      <el-date-picker
        class="mt2"
        v-model="buydate"
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="校准日期"
      >
      </el-date-picker>
      <div class="mt2">
        <span>状态：</span>
        <el-radio v-model="radio" label="1">正常</el-radio>
        <el-radio v-model="radio" label="2">其它</el-radio>
      </div>
      <el-input placeholder="请输入备注" class="mt2" v-model="marks">
        <template slot="prepend">备注</template>
      </el-input>

      <el-upload
        name="upFile"
        class="upload-demo"
         :action='$base+"/api/index/cusupload" '
        :on-change="handleChange"
        multiple
        :file-list="fileList"
      >
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">上传文件</div>
      </el-upload>

      <el-button type="primary" class="mt2 bt" @click="sub">提交</el-button>

      <van-divider />
    </div>
  </div>
</template>
<script>
import { WOW } from "wowjs";
import BMap from "BMap";
export default {
  name: "Upload",
  data() {
    return {
      user: "",
      radio: "",
      marks: "",
      guige: "",
      dname: "",
      dnum: "",
      buydate: "",
      fileList: [],
    };
  },
  mounted() {
    let suer = JSON.parse(localStorage.getItem("user"));
    this.user = suer;
    var wow = new WOW();
    wow.init();
    this.get_konw();
  },
  methods: {
    sub() {
      //   console.log('ff:',this.fileList);

     

      console.log("ff:",this.dnum);

      if (!this.dnum) {
        alert("请输入编号");
        return;
      }
      if (!this.dname) {
        alert("请输入名称");
        return;
      }
      if (!this.guige) {
        alert("请输入规格");
        return;
      }
      if (!this.buydate) {
        alert("请选择日期");
        return;
      }
      if (!this.fileList.length) {
        alert("请上传文件");
        return;
      }

       let ff = this.fileList;
      let f_arr = [];

      if (ff.length) {
        for (let i in ff) {
          f_arr.push(ff[i].response.data);
        }
      } else {
        f_arr = "";
      }

      let dd = {
        uid: this.user[0].id,
        dnum: this.dnum,
        dname: this.dname,
        guge: this.guige,
        state: this.radio,
        buydate: this.buydate,
        linkurl: f_arr.length ? f_arr.toString() : "",
        marks: this.marks,
      };
      console.log("ddd:", dd); 
      this.http.post('/products/deviceup',dd).then(res=>{
          console.log('deviceup:',res);
          alert(res.data.msg)
      })

    },
    handleChange(file, fileList) {
      this.fileList = fileList;
      console.log('666:',fileList)
    },
    go_xq(e) {
      this.$router.push({ path: "/konwxq", query: { info: e } });
    },
    timeTrans(date) {
      var date = new Date(date * 1000);
      var Y = date.getFullYear() + "-";
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
      var h =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var m =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var s =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m + s;
    },

    get_konw() {
      let v = this;
      this.http.post("/products/getculmsg").then((res) => {
        console.log("知识库:", res);
        if (res.data.code == 1) {
          v.list = res.data.data;

          let dd = res.data.data;
          for (let i of dd) {
            let tt = v.timeTrans(i.createtime);
            v.time.push(tt);
          }
        } else {
          alert(res.data.msg);
        }
      });
    },
  },
};
</script>
<style scoped>
.bt {
  width: 50vw;
}
.center {
  display: flex;
  align-items: center;
  width: 100%;
  justify-content: center;
  flex-direction: column;
}
.banner {
  color: #fff;
  font-size: 30px;
  height: 150px;
  line-height: 150px;
  background-image: url("../assets/img/banner_1.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: scroll;
  background-position: center center;
}
.ContactUs-container {
  padding: 80px 0;
  transition: all ease 0.5s;
  box-sizing: border-box;
}
#map {
  width: 100%;
  height: 365px;
}
.row {
  margin-right: 0;
  margin-left: 0;
}
@media screen and (max-width: 997px) {
  .ContactUs-container {
    padding: 20px 0;
  }
}
</style>

